/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TiepNhanDaiLyInternalFrame.java
 *
 * Created on Jul 8, 2010, 8:37:00 PM
 */

package GUI;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author May2
 */
public class TiepNhanCuaHangInternalFrame extends javax.swing.JInternalFrame {

//    public void hienThiDanhSachDaiLy(){
//        ArrayList<DaiLyPOJO> list = DaiLyBUS.selectDaiLy();
//        //Tạo các cột trên jtbDanhSach
//        DefaultTableModel dtm = new DefaultTableModel();
//        dtm.addColumn("Mã Đại Lý");
//        dtm.addColumn("Tên Đại Lý");
//        dtm.addColumn("Loại Đại Lý");
//        dtm.addColumn("Điện Thoại");
//        dtm.addColumn("Địa Chỉ");
//        dtm.addColumn("Quận");
//        dtm.addColumn("Ngày Tiếp Nhận");
//        dtm.addColumn("Email");
//
//        //Tạo model
//        dtm.setRowCount(list.size());
//        for(int i=0; i<list.size(); i++){
//            dtm.setValueAt(list.get(i).getMaDaiLy(), i, 0);
//            dtm.setValueAt(list.get(i).getTenDaiLy(), i, 1);
//            dtm.setValueAt(list.get(i).getLoaiDaiLy(), i, 2);
//            dtm.setValueAt(list.get(i).getDienThoai(), i, 3);
//            dtm.setValueAt(list.get(i).getDiaChi(), i, 4);
//            dtm.setValueAt(list.get(i).getQuan(), i, 5);
//
//            String ngay = list.get(i).getNgayTiepNhan();
//            String array_ngay[] = ngay.split("-");
//            String ngayTiepNhan = "";
//            for(int j=3; j>0; j--){
//                ngayTiepNhan += array_ngay[j-1];
//                if(j!=1){
//                    ngayTiepNhan += "-";
//                }
//            }
//            dtm.setValueAt(ngayTiepNhan, i, 6);
//            
//            dtm.setValueAt(list.get(i).getEmail(), i, 7);
//        }
//
//        //Gán model cho JTable
//        this.jtbDanhSach.setModel(dtm);
//        this.jtbDanhSach.changeSelection(0, 0, false, false);
//    }

    public void hienThiQuan(){
//        ArrayList<DaiLyPOJO> list = DaiLyBUS.selectQuan();
//        //Đọc dữ liệu
//        DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
//        for(int i=0; i<list.size(); i++){
//            //Đọc từng dòng
//            Vector ct = new Vector();
//            ct.add(list.get(i).getMaQuan());
//            ct.add(list.get(i).getQuan());
//            //Thêm một dòng vào model của JComboBox
//            dcbm.addElement(ct);
//        }
//        //Gán model cho JComboBox
//        this.jcbQuan.setModel(dcbm);
    }

    public void hienThiLoaiDaiLy(){
//        ArrayList<DaiLyPOJO> list = DaiLyBUS.selectLoaiDaiLy();
//        //Đọc dữ liệu
//        DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
//        for(int i=0; i<list.size(); i++){
//            //Đọc từng dòng
//            Vector ct = new Vector();
//            ct.add(list.get(i).getMaLoaiDaiLy());
//            ct.add(list.get(i).getLoaiDaiLy());
//            //Thêm một dòng vào model của JComboBox
//            dcbm.addElement(ct);
//        }
//        //Gán model cho JComboBox
//        this.jcbLoaiDaiLy.setModel(dcbm);
    }

    /** Creates new form TiepNhanDaiLyInternalFrame */
    public TiepNhanCuaHangInternalFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jlbTenDaiLy = new javax.swing.JLabel();
        jtfTenDaiLy = new javax.swing.JTextField();
        jlbDienThoai = new javax.swing.JLabel();
        jlbDiaChi = new javax.swing.JLabel();
        jtfDienThoai = new javax.swing.JTextField();
        jtfDiaChi = new javax.swing.JTextField();
        jbtThem = new javax.swing.JButton();
        jbtThoat = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtbDanhSach = new javax.swing.JTable();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle("TIEP NHAN CUA HANG");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jlbTenDaiLy.setText("Tên Cửa Hàng :");

        jlbDienThoai.setText("Điện Thoại :");

        jlbDiaChi.setText("Địa Chỉ :");

        jbtThem.setText("Thêm");
        jbtThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtThemActionPerformed(evt);
            }
        });

        jbtThoat.setText("Thoát");
        jbtThoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtThoatActionPerformed(evt);
            }
        });

        jtbDanhSach.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jtbDanhSach);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(159, 159, 159)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jlbTenDaiLy)
                    .addComponent(jbtThem, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlbDienThoai)
                    .addComponent(jlbDiaChi))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jbtThoat, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfTenDaiLy, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)
                    .addComponent(jtfDiaChi, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)
                    .addComponent(jtfDienThoai))
                .addContainerGap())
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 478, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbTenDaiLy)
                    .addComponent(jtfTenDaiLy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbDienThoai)
                    .addComponent(jtfDienThoai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlbDiaChi))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtThem)
                    .addComponent(jbtThoat))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(32, 32, 32))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        // TODO add your handling code here:
//////        this.hienThiDanhSachDaiLy();
//////        this.hienThiQuan();
//////        this.hienThiLoaiDaiLy();
//////        Date now = new Date();
//////        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
//////        String d = sdf.format(now);
//////        this.jtfNgayTiepNhan.setText(d);
    }//GEN-LAST:event_formInternalFrameOpened

    private void jbtThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtThemActionPerformed
        // TODO add your handling code here:
//        String tenDaiLy = this.jtfTenDaiLy.getText();
//        String diaChi = this.jtfDiaChi.getText();
//        String dienThoai = this.jtfDienThoai.getText();
//        String email = this.jtfEmail.getText();
//
//        String ngay = this.jtfNgayTiepNhan.getText();
//        String array_ngay[] = ngay.split("-");
//        String ngayTiepNhan = "";
//        for(int i=3; i>0; i--){
//            ngayTiepNhan += array_ngay[i-1];
//            if(i!=1){
//                ngayTiepNhan += "-";
//            }
//        }
//
//        Vector vtQuan = (Vector)this.jcbQuan.getSelectedItem();
//        int maQuan = (Integer)vtQuan.get(0);
//        Vector vtLoaiDaiLy = (Vector)this.jcbLoaiDaiLy.getSelectedItem();
//        int maLoaiDaiLy = (Integer)vtLoaiDaiLy.get(0);
//
//        if(DaiLyBUS.isFullSoDaiLyCuaQuan(maQuan)){
//            JOptionPane.showMessageDialog(this, "Số đại lý của quận đã đạt tối đa!!!");
//        } else{
//            int n = DaiLyBUS.insertDaiLy(tenDaiLy, maLoaiDaiLy, dienThoai, diaChi, maQuan, ngayTiepNhan, email);
//            if(n==1){
//                    JOptionPane.showMessageDialog(this, "Thêm thành công!!!");
//                    this.hienThiDanhSachDaiLy();
//            } else {
//                    JOptionPane.showMessageDialog(this, "Thêm thất bại.");
//            }
//        }
    }//GEN-LAST:event_jbtThemActionPerformed

    private void jbtThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtThoatActionPerformed
        // TODO add your handling code here:
        int reply = JOptionPane.showConfirmDialog(this, "Bạn có muốn thoát", "Thông báo", WIDTH);
        if(reply == JOptionPane.OK_OPTION){
            this.dispose();
        }
    }//GEN-LAST:event_jbtThoatActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtThem;
    private javax.swing.JButton jbtThoat;
    private javax.swing.JLabel jlbDiaChi;
    private javax.swing.JLabel jlbDienThoai;
    private javax.swing.JLabel jlbTenDaiLy;
    private javax.swing.JTable jtbDanhSach;
    private javax.swing.JTextField jtfDiaChi;
    private javax.swing.JTextField jtfDienThoai;
    private javax.swing.JTextField jtfTenDaiLy;
    // End of variables declaration//GEN-END:variables

}
